package com.example.zhongshuishi;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configurable
@Component
public class MyIntercepter implements WebMvcConfigurer {

    @Autowired
    LogginAuthIntercepter logginAuthIntercepter;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        try {
            registry.addInterceptor(logginAuthIntercepter).addPathPatterns("/api/**").excludePathPatterns("/**/login/**","/**/sms/**");
        }catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        try {
            registry.addMapping("/api/**").allowedOriginPatterns("*").allowedMethods("*").allowedHeaders("*").allowCredentials(true).maxAge(60 * 30);
        }catch (Exception e) {
            e.printStackTrace();
        }

    }
}
